package com.example.imtoken.room.dao

import androidx.room.*
import com.example.imtoken.room.schema.AccountSchema

@Dao
interface AccountDao {

    @Insert
    fun insertAccount(accountEntity: AccountSchema): Long

    @Query("SELECT * FROM account")
    fun getAllAccountWallet(): MutableList<AccountSchema>

    /**
     * 验证钱包密码
     * @param address String?
     * @param pass String?
     * @return Int
     */
    @Query("SELECT COUNT(*) FROM account WHERE address = :address AND password = :pass")
    fun findWalletPass(address: String?, pass: String?): Int

    /**
     * 根据货币地址查询默认货币
     * @param address String?
     * @return LiveData<AccountSchema>
     */
    @Query("SELECT * FROM account WHERE address = :address")
    fun getDefAccount(address: String?): AccountSchema

    @Update
    fun updateAccount(accountEntity: AccountSchema): Int

    /**
     * 根据地址查询该货币是否存在
     * @param address String?
     * @return Int
     */
    @Query("SELECT count(*) FROM account WHERE address = :address")
    fun findAccountExist(address: String?): Int

    @Query("DELETE FROM account WHERE address = :address")
    fun deleteAccount(address: String?): Int

    /**
     * 查询身份的主钱包
     * @return AccountSchema
     */
    @Query("SELECT * FROM account WHERE type = 1 AND coin = 'eth'")
    fun findOwnerData(): AccountSchema

    /**
     * 查询身份钱包
     * @return MutableLiveData<AccountSchema>
     */
    @Query("SELECT * FROM account WHERE type = 1")
    fun findAdminAccount(): MutableList<AccountSchema>

    @Query("DELETE FROM account")
    fun delete(): Int

}